import urllib.request as ur
import urllib.parse as up
import json
word = input('请输入想要翻译的中/英文:')
data = {
    'kw':word
}
data_url = up.urlencode(data) #对url地址进行编码
request = ur.Request(
    url='https://fanyi.baidu.com/sug',
    data=data_url.encode('utf-8'),
)
response = ur.urlopen(request).read() #打开请求网站
ret = json.loads(response)
translate = ret['data'][0]['v']
print(translate)


